package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.data.EatShowUserInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;


/**
 * Created by windo on 2015/11/26.
 */
public class GetUserInfoTask extends CouponHttpBaseTask {
    private String mUserId;

    public GetUserInfoTask(String userid) {
        super(TaskType.GET_USERINFO_TASK);
        mUserId = userid;
    }

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        {
            JSONObject json = response.getBody();
            EatShowUserInfo userInfo = null;
            if (json != null) {
                userInfo = JSON.parseObject(json.getString("data"), EatShowUserInfo.class);
            }
            notifyTaskCompleted(TaskResultCode.SUCCESS, userInfo);
        }
    }

    @Override
    protected void prepareRequest() {
        {
            super.prepareRequest();
            if (mPhase == TASK_PHASE_INIT) {
                CouponHttpRequest request = new CouponHttpRequest(RequestType.GET_USERINFO_REQUEST);
                JSONObject jsonData = new JSONObject();
                jsonData.put("userId", mUserId);
                request.setData(jsonData.toString());
                request.setApiNo(ApiNo.GET_USERINFO);
                addRequest(request);
            }
        }
    }
}
